import { getUserList } from '../api'
import { getUser } from '../api';
import { getdList } from '../api';
import { getdUser } from '../api';
import { addUser } from '../api';
import { delUser } from '../api';
//import axios from 'axios'
const state = {
    userlist:[],
    user:{},
    duserlist: [],
    duser: {},
    isShow:false,
};
const mutations = {
    isShow(state){
        state.isShow=!state.isShow
    },
    USERLIST(state, userlist){
        
        state.userlist=userlist 
    },
    USER(state, user) {

        state.user = user
       
    },
    DUSERLIST(state, duserlist) {

        state.duserlist = duserlist
    },
    DUSER(state, duser) {

        state.duser = duser
        
    }

};
const actions = {
    //查找所有用户
    async userList({commit}){
        let result =await getUserList();
        
        if (result.status == 200) {
            
            commit("USERLIST", result.data);
        }
    },
    //通过电话查找用户
      async userbytel({ commit },tel=[]) {
          let result = await getUser(tel);

        console.log(tel)
        if (result.status == 200) {
              
            commit("USER", result.data);
        }
    },
    //查找所有派送员
    async dList({ commit }) {
        let result = await getdList();
        if (result.status == 200) {
            commit("DUSERLIST", result.data);
        }
    },
    //通过电话查找派送员
    async duserbytel({ commit }, tel = []) {
        let result = await getdUser(tel);
        if (result.status == 200) {

            commit("DUSER", result.data);
        }
    },
     //添加派送员
    async adduser({ commit }, tel = []) {
        await addUser(tel);
        if (result.status == 200) {
            
            return "ok"
        }
    },
    //删除派送员
     async deluser({ commit }, id = []) {
         await delUser(id);
        if (result.status == 200) {

            return "ok"
        }
    }
};
const getters = {};


export default {

    state,
    mutations,
    actions,
    getters
}